#!/bin/bash

echo "=== War3代理调试测试 ==="

# 检查二进制文件
if [ ! -f "target/release/war3-server" ] || [ ! -f "target/release/war3-client" ]; then
    echo "❌ 二进制文件不存在，请先编译"
    exit 1
fi

echo "✅ 二进制文件检查通过"

# 创建日志目录
mkdir -p logs

echo ""
echo "=== 测试步骤 ==="
echo "1. 在终端1启动服务器："
echo "   ./target/release/war3-server --ip 0.0.0.0 --port 8888"
echo ""
echo "2. 在终端2启动客户端A（机器A）："
echo "   ./target/release/war3-client --server-ip 127.0.0.1 --local-ip 10.0.9.21 > logs/client_a.log 2>&1"
echo ""
echo "3. 在终端3启动客户端B（机器B）："
echo "   ./target/release/war3-client --server-ip 127.0.0.1 --local-ip 10.0.9.22 > logs/client_b.log 2>&1"
echo ""
echo "4. 观察日志输出，特别关注："
echo "   - 'Creating War3Server for new client IP' 消息"
echo "   - 'Found X war3 servers to forward to' 消息"
echo "   - 数据转发是否正常"
echo ""
echo "5. 在War3游戏中创建房间，检查另一台机器是否能看到"
echo ""
echo "=== 调试命令 ==="
echo "查看客户端A日志："
echo "   tail -f logs/client_a.log | grep -E '(Creating|Found|forward)'"
echo ""
echo "查看客户端B日志："
echo "   tail -f logs/client_b.log | grep -E '(Creating|Found|forward)'"
echo ""
echo "=== 修复说明 ==="
echo "本次修复解决了客户端列表更新时没有为新客户端创建War3Server的问题"
echo "现在当收到CLIENT_LIST_UPDATE消息时，会为每个新客户端创建对应的War3Server"
echo "这样就能正确转发UDP广播数据到其他客户端了"